using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;

namespace DOTS.DOD.LESSON7
{
    struct CubeGenerator : IComponentData
    {
        public Entity CubeProtoType;
        public int GenerationTotalCount;
        public int GenerationNumPerTick;
        public float TickTime;
        public float3 GeneratorAreaPos;
        public float3 GeneratorAreaSize;
        public float3 TargetAreaPos;
        public float3 TargetAreaSize;
        public float RotateSpeed;
        public float MoveSpeed;
    }

    public class CubeGeneratorAuthoring : MonoBehaviour
    {
        public GameObject CubeArchetype;
        public int GenerationTotalCount;
        public int GenerationNumPerTick;
        public float TickTime;
        public float3 GeneratorAreaPos;
        public float3 GeneratorAreaSize;
        public float3 TargetAreaPos;
        public float3 TargetAreaSize;
        public float RotateSpeed;
        public float MoveSpeed;

        class Baker : Baker<CubeGeneratorAuthoring>
        {
            public override void Bake(CubeGeneratorAuthoring authoring)
            {
                var entity = GetEntity(TransformUsageFlags.None);
                AddComponent(entity, new CubeGenerator()
                {
                    CubeProtoType = GetEntity(authoring.CubeArchetype, TransformUsageFlags.Dynamic),
                    GenerationTotalCount = authoring.GenerationTotalCount,
                    GenerationNumPerTick = authoring.GenerationNumPerTick,
                    TickTime = authoring.TickTime,
                    GeneratorAreaPos = authoring.GeneratorAreaPos,
                    GeneratorAreaSize = authoring.GeneratorAreaSize,
                    TargetAreaPos = authoring.TargetAreaPos,
                    TargetAreaSize = authoring.TargetAreaSize,
                    RotateSpeed = authoring.RotateSpeed,
                    MoveSpeed = authoring.MoveSpeed,
                });
            }
        }
    }
}